import { Column, Entity, Index } from 'typeorm';
import { BaseEntity } from '../../base/entity/base';

/**
 * 质保金操作类型
 */
export enum DepositOperationType {
  /** 缴纳 */
  PAY = 'pay',
  /** 退还 */
  REFUND = 'refund',
  /** 扣除 */
  DEDUCT = 'deduct',
}

/**
 * 质保金记录状态
 */
export enum DepositRecordStatus {
  /** 待支付 */
  PENDING = 0,
  /** 已完成 */
  COMPLETED = 1,
  /** 已取消 */
  CANCELLED = 2,
  /** 已退还 */
  REFUNDED = 3,
}

@Entity('provider_deposit', { comment: '服务人员质保金记录' })
export class ProviderDepositEntity extends BaseEntity {
  @Index()
  @Column({ comment: '服务人员ID', nullable: false })
  providerId: number;

  @Column({
    comment: '操作类型',
    type: 'varchar',
    length: 20,
    default: DepositOperationType.PAY,
  })
  operationType: DepositOperationType;

  @Column({
    comment: '金额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    nullable: false,
  })
  amount: number;

  @Column({
    comment: '操作前余额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0,
  })
  beforeBalance: number;

  @Column({
    comment: '操作后余额',
    type: 'decimal',
    precision: 10,
    scale: 2,
    default: 0,
  })
  afterBalance: number;

  @Column({
    comment: '状态',
    dict: ['待支付', '已完成', '已取消', '已退还'],
    default: DepositRecordStatus.PENDING,
  })
  status: DepositRecordStatus;

  @Column({ comment: '支付订单号', length: 100, nullable: true })
  orderNo?: string;

  @Column({ comment: '第三方支付流水号', length: 100, nullable: true })
  transactionId?: string;

  @Column({ comment: '支付方式', length: 50, nullable: true })
  payMethod?: string;

  @Column({ comment: '备注', length: 500, nullable: true })
  remark?: string;

  @Column({ comment: '操作人ID（管理员扣除时）', nullable: true })
  operatorId?: number;

  @Column({ comment: '支付时间', type: 'datetime', nullable: true })
  paidAt?: Date;
}

